<template>
  <div class="comment-reply">
    <!-- 导航栏 -->
    <van-nav-bar :title="`${comment.reply_count}条回复`">
      <van-icon slot="left" @click="close_popup" name="cross" />
    </van-nav-bar>
    <!-- /导航栏 -->

    <!-- 当前评论项 -->
    <commentItem :comment="comment"></commentItem>
    <!-- /当前评论项 -->

    <van-cell title="所有回复" />

    <!-- 评论的回复列表 -->

    <van-list
      v-model="loading"
      v-if="ReplyShow"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell title="文章评论"></van-cell>
      <commentItem v-for="(item, i) in list" :key="i" :comment="item" />
    </van-list>

    <!-- /评论的回复列表 -->

    <!-- 底部 -->

    <!-- /底部 -->
  </div>
</template>

<script>
// 导入 评论项 组件
import commentItem from './comment_itme.vue'
// 导入 评论的 回复消息
import { getComments } from '@/api/user.js'
export default {
  name: 'CommentReply',
  components: { commentItem },
  props: {
    comment: {
      type: Object
    }
  },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      ReplyShow: false
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  //   使用到祖先组件里的数据
  inject: ['closeReplyShow', 'isReplyShow'],
  methods: {
    async onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      const { data } = await getComments({
        type: 'c',
        source: this.comment.com_id,
        limit: this.limit
      })
      console.log(data.data.results)
      this.list = data.data.results
    },
    close_popup() {
      this.closeReplyShow()
      this.ReplyShow = this.sReplyShow
    }
  }
}
</script>

<style scoped></style>
